package com.leyou.Service;

import com.leyou.Mapper.SpecGroupMapper;
import com.leyou.Mapper.SpecParamMapper;
import item.pojo.SpecGroup;
import item.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecificationService {
    @Autowired
    private SpecGroupMapper specGroupMapper;
    @Autowired
    private SpecParamMapper specParamMapper;

    public List<SpecGroup> querySpecGroups(Long cid) {
        SpecGroup t = new SpecGroup();
        t.setCid(cid);
        List<SpecGroup> specGroups = this.specGroupMapper.select(t);

        specGroups.forEach(group->{
            SpecParam specParam=new SpecParam();
            specParam.setGroupId(group.getId());
            group.setParams(specParamMapper.select(specParam));
        });
        return specGroups;
    }

    public List<SpecParam> querySpecParams(Long gid, Long cid, Boolean searching, Boolean generic) {
        SpecParam t = new SpecParam();
        t.setGroupId(gid);
        t.setCid(cid);
        t.setSearching(searching);
        t.setGeneric(generic);
        return this.specParamMapper.select(t);
    }
}
